package com.itheima.utildemo;

import javax.management.relation.RoleUnresolved;
import javax.swing.*;
import java.util.concurrent.CountDownLatch;

public class Demo02 {

    public static void main(String[] args) {
        CountDownLatch count = new CountDownLatch(8);
        CaiPan caiPan = new CaiPan(count);
        Thread t1 = new Thread(caiPan);
        t1.start();
        for (int i = 0; i < 8; i++) {
            YunDongYuan yundongyuan = new YunDongYuan(count);
            Thread t = new Thread(yundongyuan);
            t.setName("运动员00"+i+"号");
            t.start();
        }


    }
}
class CaiPan implements Runnable{
    private CountDownLatch count;

    public CaiPan(CountDownLatch count) {
        this.count = count;
    }

    @Override
    public void run() {
        //准备打枪
        try {
            //等着
            count.await();
            //等所有人到齐了  打枪
            System.out.println("各就位,预备 ,嘭");

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
class  YunDongYuan implements Runnable{
    private CountDownLatch count;

    public YunDongYuan(CountDownLatch count) {
        this.count = count;
    }

    @Override
    public void run() {
        // 来了告诉裁判我到了
        System.out.println(Thread.currentThread().getName()+"已就位");
        count.countDown();
    }
}